﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using MyBet.Class;
using MyBet.Helpers;
using MyBet.Web;

namespace MyBet
{
    public partial class MatchView : ChildWindow
    {
        #region Attributes
        private Guid _userId;
        private int _eventId;
        private MatchsList _matchs;
        private GetRanksSvc.RankObject _currentRank;
        #endregion

        #region Properties

        public GetRanksSvc.RankObject CurrentRank
        {
            get { return _currentRank; }
            set { _currentRank = value; }
        }

        public Guid UserId
        {
            get { return _userId; }
            set { _userId = value; }
        }

        public int EventId
        {
            get { return _eventId; }
            set { _eventId = value; }
        }

        public MatchsList Matchs
        {
            get { return _matchs; }
            set { _matchs = value; }
        }
        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="userId">User to spy</param>
        /// <param name="eventId">Event to view</param>
        public MatchView(GetRanksSvc.RankObject rank, int eventId)
        {
            InitializeComponent();
            this.CurrentRank = rank;
            this.UserId = rank._userId;
            this.EventId = eventId;
            UpdateCulture();
            BusyControl.IsBusy = true;
            this.IsEnabled = false;
            Matchs = new MatchsList(MatchStack);
            Matchs.OnLoaded += new MatchsList.Loaded(Matchs_OnLoaded);
            Matchs.Status = DaysList.DayStatus.Finished;
            Matchs.LoadUserEvent(this.UserId, eventId); 
        }

        void Matchs_OnLoaded()
        {
            this.IsEnabled = true;
            BusyControl.IsBusy = false;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        /// <summary>
        /// Mise à jour des libellés
        /// </summary>
        public void UpdateCulture()
        {
            this.Title = String.Format(LangHelper.GetString("MatchViewTitle"), CurrentRank._userName);
            OKButton.Content = LangHelper.GetString("CloseButton");
            BusyControl.BusyContent = LangHelper.GetString("WaitingLoad");
            EventServiceReference.EventObject currentEvent = EventHelper.GetEventFromId(App.EventsDictionary, EventId);
            if (currentEvent != null)
            {
                EventTitle.Text = EventHelper.GetEventName(currentEvent);
            }
        }

    }
}

